package com.jch.helloworld.configBeans.lifeCycle;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

// bean后置处理器
public class DemoBeanPostProcessor implements BeanPostProcessor {

    // 在调用bean初始化方法之前调用
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessBeforeInitialization: (beanClassName: " + bean.getClass().getName() + ") beanName: " + beanName);
        return bean;
    }

    // 在调用bean初始化方法之后调用
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessAfterInitialization: (beanClassName: " + bean.getClass().getName() + ") beanName: " + beanName);
        return bean;
    }
}
